<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
    /*   function Person(name,age){
           this.name = name;
           this.age = age;
       }

       Person.prototype.sayName = function(){
           return this.name
       }

       let p = new Person('jack',21);
       console.log(p)*/

    class Person {
        constructor(name, age) {
            this.name = name
            this.age = age
        }
        getName(){
            return this.name
        }
        getAge(){
            return this.age
        }
    }

    // 可以通过Object.assign一次性向类中添加多个方法
    Object.assign(Person.prototype,{
        sayName(){
            return this.name
        },
        sayTime(){
            return new Date().getTime()
        }
    })

    let p = new Person('james',30)
    console.log(p)
</script>
</body>
</html>
